<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="订单号" prop="code">
				<el-input v-model="queryParams.code" placeholder="" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="更改人ID" prop="userId">
				<el-input v-model="queryParams.userId" placeholder="" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<!-- <el-form-item label="分类" prop="categoryId">
				<el-select v-model="queryParams.categoryId" filterable placeholder="请选择分类" clearable @change="handleQuery">
					<el-option v-for="item in articleCategoryList" :key="item.id" :label="item.name" :value="item.id"></el-option>
				</el-select>
			</el-form-item> -->
			<el-form-item label="订单状态" prop="roleAuditStatus">
				<el-select v-model="queryParams.roleAuditStatus" filterable placeholder="请选择分类" clearable @change="handleQuery">
					<el-option label="全部" value=""></el-option>
					<el-option label="待审核" :value="0"></el-option>
					<el-option label="审核通过" :value="1"></el-option>
					<el-option label="拒绝" :value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['biz:deduction:goods:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['biz:deduction:goods:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['biz:deduction:goods:remove']">删除</el-button>
			</el-col> -->
			<!-- <el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['biz:deduction:goods:export']">导出</el-button>
			</el-col> -->
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="申请人" align="center" prop="" width="300px">
				<template slot-scope="scope">
					<div>
						<div v-if="scope.row.changedUser">
							<div>申请人ID：{{scope.row.changedUser.userId}}</div>
							<div>申请人昵称：{{scope.row.changedUser.nickName}}</div>
							<div>申请人角色：{{scope.row.changedUser.sysRoleName.toString()}}</div>
							<div>申请人手机号：{{scope.row.changedUser.poneName}}</div>
						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column label="创建人" align="center" prop="" width="300px">
				<template slot-scope="scope">
					<div>
						<div v-if="scope.row.modifierInfo">
							<div>创建人ID：{{scope.row.modifierInfo.userId}}</div>
							<div>创建人昵称：{{scope.row.modifierInfo.nickName}}</div>
							<div>创建人角色：{{scope.row.modifierInfo.sysRoleName.toString()}}</div>
							<div>创建人手机号：{{scope.row.modifierInfo.poneName}}</div>
						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column label="订单编号" prop="code" width='140'></el-table-column>
			<el-table-column label="投资金额" prop="amount"></el-table-column>
			<el-table-column label="角色" prop="roleName"></el-table-column>
			<el-table-column label="付款凭证" prop="paymentVoucher"></el-table-column>
			<el-table-column label="拒绝原因" prop="auditRejectReason"></el-table-column>

			<el-table-column label="创建时间" prop="createTime" width='150'></el-table-column>

			<el-table-column label="状态" prop="statusName" width='100' fixed='right'>
				<template slot-scope="scope">
					<div class="flex-center">
						<div>
							<!-- 0 待审核 1 审核通过 2 审核拒绝-->
							<el-tag :type="
							scope.row.roleAuditStatus ==''?'warning':
							scope.row.roleAuditStatus =='1'?'success':
							scope.row.roleAuditStatus =='2'?'danger':
							'info' ">{{scope.row.statusDesc}}</el-tag>

						</div>
					</div>
				</template>
			</el-table-column>
			<el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button type="text" v-if="scope.row.roleAuditStatus == '0'" size="mini" @click="update_VipOrder(scope.row)">
						审核
					</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

	</div>
</template>

<script>
import {
	list_VipOrder,
	get_VipOrder,
	del_VipOrder,
	update_VipOrder,
} from '@/api/system/user';

export default {
	name: 'Goods',
	data() {
		return {
			articleCategoryList: [],
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// biz_商品管理表格数据
			goodsList: [],
			// 弹出层标题
			title: '',
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				type: null,
				categoryId: null,
				storeId: null,
				stock: null,
				unit: null,
				originalPrice: null,
				points: null,
				desc: null,
				preferentialPrice: null,
				imgUrl: null,
				img2Url: null,
				sort: null,
				limitedPurchaseQuantity: null,
				videoUrl: null,
				startTime: null,
				endTime: null,
				status: null,
				isShowDetail: null,
				isShowVideo: null,
				content: null,
				soldQuantity: null,
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {},
		};
	},
	created() {
		this.getList();
		// this.listGoodsCategory();
	},
	activated() {
		// this.listGoodsCategory();
	},
	methods: {
		update_VipOrder: function (row) {
			this.$prompt('请选择通过审核或者不通过,可输入备注原因', '审核', {
				distinguishCancelAndClose: true,
				confirmButtonText: '通过',
				cancelButtonText: '不通过',

				// inputValue: row.manualRefundAmt,
				// inputPattern:
				// 	/((^([1-9]{1}\d*)(\.{0,1}\d{1,2}$|$))|(^(0{1})(?=(\.{1}\d{1,2}$|$))))/,
			})
				.then(({ value }) => {
					const params = {
						code: row.code,
						roleAuditStatus: 1,
						auditRejectReason: value || '',
					};
					update_VipOrder(params).then((response) => {
						this.$message.success('操作成功');
						this.getList();
					});
				})
				.catch((action) => {
					if (action === 'cancel') {
						const params = {
							code: row.code,
							roleAuditStatus: 2,
							auditRejectReason:   '不通过',
						};
						update_VipOrder(params).then((response) => {
							this.$message.success('操作成功');
							this.getList();
						});
					}
				});
		},
		/** 查询biz_分类管理列表 */
		listGoodsCategory() {
			listGoodsCategory({
				pageSize: 100,
			}).then((response) => {
				this.articleCategoryList = response.rows;
			});
		},
		/** 查询biz_商品管理列表 */
		getList() {
			this.loading = true;
			list_VipOrder(this.queryParams).then((response) => {
				this.goodsList = response.rows;
				this.total = response.total;
				this.loading = false;
			});
		},
		// 取消按钮
		cancel() {
			this.open = false;
			this.reset();
		},
		// 表单重置
		reset() {
			this.form = {
				id: null,
				type: null,
				categoryId: null,
				storeId: null,
				stock: null,
				unit: null,
				originalPrice: null,
				points: null,
				desc: null,
				preferentialPrice: null,
				imgUrl: null,
				img2Url: null,
				sort: null,
				limitedPurchaseQuantity: null,
				videoUrl: null,
				startTime: null,
				endTime: null,
				status: 0,
				isShowDetail: null,
				isShowVideo: null,
				content: null,
				soldQuantity: null,
				createByName: null,
				createById: null,
				createTime: null,
				updateByName: null,
				updateById: null,
				updateTime: null,
				isDeleted: null,
				remark: null,
			};
			this.resetForm('form');
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm('queryForm');
			this.handleQuery();
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map((item) => item.id);
			this.single = selection.length !== 1;
			this.multiple = !selection.length;
		},
		/** 新增按钮操作 */
		handleAdd() {
			this.reset();
			this.open = true;
			this.title = '添加biz_商品管理';
			this.$refs.ImageUpload.fileList = [];
		},
		/** 修改按钮操作 */
		handleUpdate(row) {
			this.reset();
			const id = row.id || this.ids;
			this.open = true;
			getGoods(id).then((response) => {
				this.$refs.ImageUpload.fileList = [
					{
						url:
							this.$store.state.app.imgUrl + response.data.imgUrl,
						uploadUrl: response.data.imgUrl,
					},
				];
				if (response.data.videoUrl) {
					this.$refs.videoUpload.fileList = [
						{
							name: response.data.videoUrl,
							url: response.data.videoUrl,
						},
					];
				} else {
					this.$refs.videoUpload.fileList = [];
				}
				this.form = response.data;

				this.title = '修改biz_商品管理';
			});
		},
		/** 提交按钮 */
		submitForm() {
			if (this.$refs.ImageUpload.fileList.length) {
				var fileList = this.$refs.ImageUpload.fileList[0];
				this.form.imgUrl = fileList.uploadUrl;
			}
			this.$refs['form'].validate((valid) => {
				if (valid) {
					if (this.form.id != null) {
						updateGoods(this.form).then((response) => {
							this.$modal.msgSuccess('修改成功');
							this.open = false;
							this.getList();
						});
					} else {
						addGoods(this.form).then((response) => {
							this.$modal.msgSuccess('新增成功');
							this.open = false;
							this.getList();
						});
					}
				}
			});
		},
		/** 删除按钮操作 */
		handleDelete(row) {
			const ids = row.id || this.ids;
			this.$modal
				.confirm(
					'是否确认删除biz_商品管理编号为"' + ids + '"的数据项？'
				)
				.then(function () {
					return delGoods(ids);
				})
				.then(() => {
					this.getList();
					this.$modal.msgSuccess('删除成功');
				})
				.catch(() => {});
		},
		/** 确认退款 */
		refund_VipOrder(row) {
			const ids = row.id || this.ids;
			this.$modal
				.confirm('是否确认退款编号为"' + ids + '"的数据项？')
				.then(function () {
					refund_VipOrder({ orderId: ids }).then((response) => {
						this.$modal.msgSuccess('操作成功');
						this.getList();
					});
				})
				.catch(() => {});
		},
		/** 导出按钮操作 */
		handleExport() {
			this.download(
				'biz/goods/export',
				{
					...this.queryParams,
				},
				`goods_${new Date().getTime()}.xlsx`
			);
		},
	},
};
</script>
